package com.tucc.hello.leetcode.no1_400.no1_200.no61_80.no73;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] matrix = {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}};
        matrix = new int[][]{{0, 1, 2, 0}, {3, 4, 5, 2}, {1, 3, 1, 5}};
        matrix = new int[][]{{1, 2, 3, 4}, {5, 0, 7, 8}, {0, 10, 11, 12}, {13, 14, 15, 0}};
        solution.setZeroes(matrix);

        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                System.out.print(matrix[i][j] + " ");
            }
            System.out.println();
        }
    }

    public void setZeroes(int[][] matrix) {
        int m[] = new int[matrix.length];
        int n[] = new int[matrix[0].length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j] == 0) {
                    m[i] = 1;
                    n[j] = 1;
                    for (int mi = i - 1; mi >= 0; mi--) {
                        matrix[mi][j] = 0;
                    }
                    for (int mj = j - 1; mj >= 0; mj--) {
                        matrix[i][mj] = 0;
                    }
                } else if (m[i] == 1 || n[j] == 1) {
                    matrix[i][j] = 0;
                }
            }
        }
    }


}
